package zcjq.d912d;

public class P1 {

    public static int dp(int[] values, int M) {
        int len = values.length;
        int[][] dp = new int[len + 1][M + 1];
        for (int i = 1; i <= len; i++) {
            int value = values[i - 1];
            for (int j = 0; j <= M; j++) {
                if (j - 1 >= 0) {
                    dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - 1] + value);
                } else {
                    dp[i][j] = dp[i - 1][j];
                }
            }
        }
        return dp[len][M];
    }

    public static void main(String[] args) {
        int[] values = new int[]{5, 2, 10, 4, 6, 5};
        System.out.println(dp(values, 3));
    }
}
